#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FILE_PATH "User_Pwd.txt"

int main(int argc, char const *argv[])
{
	/* code */
	FILE* file = fopen(FILE_PATH, "a+");
	char usr_name[20];
	char usr_pwd[20];
	char line[20];
	char row[20];
	int name_exist_state;

	printf("Please input user name: ");
	scanf("%s", usr_name);

	fgets(line, 1000, file);
	printf("%s\n", line);

	// check name in database
	while(fgets(line, 1000, file)) {
		printf("Line: %s\n", line);
		sscanf(line, "%s%*s", row);
		printf("Row: %s\n", row);

		if (strcmp(usr_name, row) == 0)
		{
			/* exist */
			name_exist_state = 1;
			printf("%d\n", name_exist_state);
		} else {
			// not exist
			name_exist_state = 0;
			printf("%d\n", name_exist_state);

		}
	}
	// printf("Name Exist State: %d\n", name_exist_state);

	// if (name_exist_state == 1)
	// {
	// 	printf("This User is in the database!\n");
	// } else {
	// 	 add usr name 
	// 	fprintf(file, "%s\n", usr_name);
	// 	printf("Name Added Successfully!\n");
	// }

	return 0;
}